package nc.impl.cqrb.wms;

import java.io.UnsupportedEncodingException;

import nc.bs.dao.BaseDAO;
import nc.itf.cqrb.wms.ICheckWmsServiceForIC;
import nc.jdbc.framework.SQLParameter;
import nc.jdbc.framework.processor.ColumnProcessor;
import nc.vo.pub.BusinessException;

public class CheckWmsServiceForICImpl implements ICheckWmsServiceForIC {

	public void checkWmsStatus(String pk) throws BusinessException {
		String sql = "SELECT VUSERDEF19 from IC_GENERAL_H h  WHERE H.DR = 0 AND H.FBILLFLAG = 2 AND H.VUSERDEF20 = 'N'  AND CGENERALHID = ? ";
		BaseDAO dao = new BaseDAO();
		SQLParameter param = new SQLParameter();
		param.addParam(pk);
		String vuserdef19 = (String) dao.executeQuery(sql, param,
				new ColumnProcessor());
		if ("Y".equalsIgnoreCase(vuserdef19)) {
			throw new BusinessException("该单据已被WMS系统读取，无法进行此操作！");
		}
	}

	

public static String str2HexStr(String str) {
    char[] chars = "0123456789ABCDEF".toCharArray();
    StringBuilder sb = new StringBuilder("");
    byte[] bs = str.getBytes();
    int bit;
    for (int i = 0; i < bs.length; i++) {
        bit = (bs[i] & 0x0f0) >> 4;
        sb.append(chars[bit]);
        bit = bs[i] & 0x0f;
        sb.append(chars[bit]);
        // sb.append(' ');
    }
    return sb.toString().trim();
    }

public static String HexToUnicode(String content) {
	String enUnicode = null;
	String deUnicode = null;
	for (int i = 0; i < content.length(); i++) {
		if (enUnicode == null) {
			enUnicode = String.valueOf(content.charAt(i));
		} else {
			enUnicode = enUnicode + content.charAt(i);
		}
		if (i % 4 == 3) {
			if (enUnicode != null) {
				if (deUnicode == null) {
					deUnicode = String.valueOf((char) Integer.valueOf(enUnicode, 16).intValue());
				} else {
					deUnicode = deUnicode + String.valueOf((char) Integer.valueOf(enUnicode, 16).intValue());
				}
			}
			enUnicode = null;
		}

	}
	return deUnicode;
}
public static String UnicodeToHex(String content) {
	String enUnicode = null;
	for (int i = 0; i < content.length(); i++) {
		if (i == 0) {
			enUnicode = getHexString(Integer.toHexString(content.charAt(i)).toUpperCase());
		} else {
			enUnicode = enUnicode + getHexString(Integer.toHexString(content.charAt(i)).toUpperCase());
		}
	}
	return enUnicode;
}
private static String getHexString(String hexString) {
	String hexStr = "";
	for (int i = hexString.length(); i < 4; i++) {
		if (i == hexString.length())
			hexStr = "0";
		else
			hexStr = hexStr + "0";
	}
	return hexStr + hexString;
}


	public static void main(String[] args) {
		String msg = "中文测试";
		try {
			String msg1 = new String(msg.getBytes("UTF-8"), "UTF-8");
			System.out.println(msg1);
			System.out.println(UnicodeToHex(msg1));
			

		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}

	}

}
